<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $category = I("get.category");
        $article = I("get.article");
        if(null != $article){
            $Article = D("article");
            $Seo = D("Seo");
            $data = $Article->where("id=".$article)->find();
            $seo = $Seo ->where("id=".$article)->find();
            $this->assign("article", $data);
            $this->assign("seo", $seo);
            $this->display("article");
        }else if(null != $category){
            $this->assign("category", $category);
            $this->display("category");
        }else{
            $this->display();
        }
    }
    
    public function getArticleByCategory(){
        $c_alias = I("post.category");
        $offset = I("post.start");
        $length = I("post.length");
        $Category = D("category");
        $category = $Category->where("alias='".$c_alias."'")->find();
        $Article = D("article");
        $data = $Article->field("id,title,abstract,author,ballStar,recordTime")->where("categoryId=".$category["id"])->limit($offset, $length)->select();
        $this->assign("article", $data);
        //dump($data);
        $this->ajaxReturn($data, "JSON");
    }
    
    public function getArticleByBallStar(){
        $ballStar = I("post.ballStar");
        $offset = I("post.start");
        $length = I("post.length");
        $Article = D("article");
        $data = null;
        if(empty($ballStar)){
            $data = $Article->field("id,title,abstract,author,ballStar,snapshot")->where("ballStar is not null")->limit($offset, $length)->select();
        }else{
            $data = $Article->field("id,title,abstract,author,ballStar,snapshot")->where("ballStar=". $ballStar)->limit($offset, $length)->select();
        }
        $this->ajaxReturn($data, "JSON");
    }
    
    public function getBallStar(){
        $offset = I("post.start");
        $length = I("post.length");
        $Article = D("article");
        $data = $Article->field("id,title,abstract,author,ballStar,snapshot")->group("ballStar")->limit($offset, $length)->select();
        //$this->assign("article", $data);
        //dump($data);
        $this->ajaxReturn($data, "JSON");
    }
    
}